package com.my.attendance.dao;

import com.my.attendance.entity.Attendance;
import com.my.attendance.entity.Employee;
import com.my.attendance.util.BaseDAO;

import java.util.Date;

public class UserDao extends BaseDAO {

    public Employee checkLogin(String employee_number, String password) throws Exception{
        String sql="select * from employee where employee_number=? and password=?";
        Object[] obj ={employee_number,password};
        Employee employee = getOne(sql, new Employee(), obj);
        return employee;
    }

    public void gowork(Attendance attendance) throws Exception{
        String sql="insert into attendance(employee_number,day,start_type) values(?,?,?)";
        Object[] obj ={attendance.getEmployee_number(),attendance.getDay(),attendance.getStart_type()};
        addOrupdOrdel(sql,obj);
    }

    public void outwork(Attendance attendance) throws Exception{
        String sql="update attendance set end_time=?,end_type=?where employee_number=?";
        Object[] obj ={attendance.getEmployee_number(),attendance.getEnd_time(),attendance.getEnd_type()};
        addOrupdOrdel(sql,obj);
    }

    public void SignUser(Attendance a) throws Exception {
        String sql="update attendance set time_type=?,start_time=? ,start_type=? where employee_number=? and day=?";
        Object[] obj ={a.getTime_type(),a.getStart_time(),a.getStart_type(),a.getEmployee_number(),a.getDay()};
        addOrupdOrdel(sql,obj);
    }

    public void OutUser(Attendance a) throws Exception {
        String sql="update attendance set end_time=? ,end_type=? where employee_number=? and day=?";
        Object[] obj ={a.getEnd_time(),a.getEnd_type(),a.getEmployee_number(),a.getDay()};
        addOrupdOrdel(sql,obj);
    }
    public Attendance checkWork(String employee_number, Date day) throws Exception {
        String sql ="select * from attendance where employee_number=? and day=?;";
        Object[] obj ={employee_number,day};
        return getOne(sql, new Attendance(),obj);
    }

}
